import {ProForm, ProFormSelect, ProFormText, ProFormTextArea} from "@ant-design/pro-components";
import {useSnapshot} from "@@/exports";
import {SettingModel} from "@/models/setting";
import {message} from "antd";
import {updateSetting} from "@/services/SettingService";

const DefaultSetting = () => {
    let settingState = useSnapshot(SettingModel.state);

    const onFinish = async (formData: any) => {
        updateSetting(formData).then(() => message.success('修改成功'))
        return true
    }
    return <>
        {settingState.setting && <ProForm
            onFinish={onFinish}
            initialValues={settingState.setting}
        >
            <ProFormText name='id' hidden/>
            <ProFormSelect
                mode="multiple"
                label="新客资通知"
                name="customerNotify"
                transform={(value) => ({customerNotify: JSON.stringify(value)})}
                options={settingState.notifyChannelList.map((notify) => ({label: notify.remark, value: notify.id}))}
            />
            <ProFormTextArea
                fieldProps={{rows: 15}}
                name="customerNotifyText"
            ></ProFormTextArea>
            <ProFormSelect
                mode="multiple"
                label="新订单通知"
                name="orderNotify"
                transform={(value) => ({orderNotify: JSON.stringify(value)})}
                options={settingState.notifyChannelList.map((notify) => ({label: notify.remark, value: notify.id}))}
            />
            <ProFormTextArea
                fieldProps={{rows: 15}}
                name="orderNotifyText"
            />
        </ProForm>
        }</>
}


export default DefaultSetting